#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e4 + 10;

int n;
struct node
{
	int w, s;
}a[N];

bool cmp(node& n1, node& n2)
{
	return n1.w + n1.s < n2.w + n2.s;
}

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> a[i].w >> a[i].s;
	sort(a + 1, a + 1 + n, cmp);
	LL ans = -a[1].s, w = 0;
	for(int i = 1;i <= n;i ++)
	{
		ans = max(ans, w - a[i].s);
		w += a[i].w;
	}
	cout << ans << endl;
	return 0;
}